package spring.module.disruptor.log;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.lmax.disruptor.RingBuffer;

import lombok.extern.slf4j.Slf4j;

/**
 * 发布
 *  
 * @author Lucky Yang
 */
@Slf4j
@Component
public class LogEventPublisher {
    @Autowired
    private RingBuffer<LogEvent> logRingBuffer; 

    public void send(String message) {
        long sequence = logRingBuffer.next();
        try {
            LogEvent event = logRingBuffer.get(sequence);
            event.setMessage(message);
        } catch (Exception e) {
            log.error("", e);
        } finally {
            logRingBuffer.publish(sequence);
        }
    }    
}
